package github.kawaiior.yuanchuxiuzhen.client.gui.misc;

import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
import github.kawaiior.yuanchuxiuzhen.Yuanchuxiuzhen;
import github.kawaiior.yuanchuxiuzhen.common.container.WeaponFurnaceContainer;
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;

public class WeaponFurnaceGUI extends ContainerScreen<WeaponFurnaceContainer> {
    private static final ResourceLocation RESOURCE_LOCATION = new ResourceLocation(Yuanchuxiuzhen.MODID,"/textures/gui/weapon_furnace_block.png");

    public WeaponFurnaceGUI(WeaponFurnaceContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) {
        super(screenContainer, inv, titleIn);
        this.guiLeft=0;
        this.guiTop=0;
        this.xSize=176;
        this.ySize=166;
    }

    @Override
    public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
        this.renderBackground(matrixStack);
        super.render(matrixStack, mouseX, mouseY, partialTicks);
        this.renderHoveredTooltip(matrixStack,mouseX,mouseY);
    }

    @Override
    protected void drawGuiContainerForegroundLayer(MatrixStack matrixStack, int x, int y) {
        this.font.drawText(matrixStack,this.playerInventory.getDisplayName(),(float) this.playerInventoryTitleX,(float) this.playerInventoryTitleY,4210752);
        if (this.getContainer().tileEntity.isWorking()){
            float progress = this.getContainer().tileEntity.getItemNumber().getProgress();
            this.minecraft.textureManager.bindTexture(RESOURCE_LOCATION);

            this.blit(matrixStack, 26, 13, 0,180,13,13);
            this.blit(matrixStack, 8, 31, 0,180,13,13);
            this.blit(matrixStack, 44, 31, 0,180,13,13);
            this.blit(matrixStack, 26, 49, 0,180,13,13);
            this.blit(matrixStack, 26, 31, 0,180,13,13);
            this.blit(matrixStack, 71, 49, 0,180,13,13);

            this.blit(matrixStack, 71, 8, 0,180,13,13);

            this.blit(matrixStack, 64, 30, 0,166,(int)(63F*progress + 0.5F),14);
        }
    }

    @Override
    protected void drawGuiContainerBackgroundLayer(MatrixStack matrixStack, float partialTicks, int mouseX, int mouseY) {
        RenderSystem.color4f(1.0f,1.0f,1.0f,1.0f);
        this.minecraft.textureManager.bindTexture(RESOURCE_LOCATION);

        int x = (this.width - this.xSize) / 2;
        int y = (this.height -this.ySize) / 2;

        this.blit(matrixStack, x, y, 0,0,this.xSize,this.ySize);
    }
}
